package com.itzz.spring_zhoneHeng.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itzz.spring_zhoneHeng.base.RestResponse;
import com.itzz.spring_zhoneHeng.dao.ClassificationDao;
import com.itzz.spring_zhoneHeng.pojo.Classification;
import com.itzz.spring_zhoneHeng.pojo.User;
import com.itzz.spring_zhoneHeng.service.ClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassificationImpl implements ClassificationService {

    @Autowired
    ClassificationDao dao;

    //查询所有的用户和它的角色
    @Override
    public RestResponse queryAll(Classification classification, Integer pageNum, Integer pageSize){
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //查询所有
        List<Classification> classifications = dao.queryAll(classification);
        //添加到分页插件中
        PageInfo<Classification> userPageInfo = new PageInfo<>(classifications);
        return RestResponse.ok(userPageInfo);
    }

    //修改
    @Override
    public RestResponse update(Classification classification){
        //修改
        int i = dao.updateById(classification);
        if(i>0){
            return RestResponse.ok();
        }
        return RestResponse.fail(500,"修改失败");
    }

    //删除
    @Override
    public RestResponse delete(Integer id){
        //删除
        int i = dao.deleteById(id);
        if(i>0){
            return RestResponse.ok();
        }
        return RestResponse.fail(500,"删除失败");
    }

    //添加
    @Override
    public RestResponse add(Classification classification){
        //添加
        int i = dao.insert(classification);
        if(i>0){
            return RestResponse.ok();
        }
        return RestResponse.fail(500,"添加失败");
    }

}
